<!-- 根据数据展示文章卡片信息的组件 -->
<script setup lang="ts" name="cardMsg">
import useCardMsg from '@/components/index/card/hooks/cardMsg'
const { ImgControl, cardData } = useCardMsg()

import useTagsControl from '@/components/index/hooks/tagsControl'
const { tagsPush } = useTagsControl()
</script>

<template>
  <div id="card-content">
    <div class="card" tabindex="1" v-for="card in cardData" :key="card.id">
      <nav>
        <span>{{ card.title }}</span>
        <router-link :to="{ name: 'info', query: { id: card.authorId } }">
          <img :src="card.authorImg" title="" />
          <b>{{ card.authorName }}</b>
        </router-link>
      </nav>
      <component :is="ImgControl" :card="card"></component>
      <section>
        <div class="flex gap-2">
          <el-tag @click="tagsPush(tag)" v-for="(tag, index) in card.tag" :key="index">{{
            tag
          }}</el-tag>
        </div>
      </section>
      <footer>
        <span class="card-time">{{ card.time }}</span>
        <span>{{ '---' }}</span>
        <span class="card-views">
          <span><Star class="svg" /></span>
          <span>{{ card.followed || 0 }}</span>
          <span><View class="svg" /></span>
          <span>{{ card.views || 0 }}</span>
        </span>
      </footer>
    </div>
  </div>
</template>

<style scoped lang="less">
* {
  color: var(--color-font);
}
.svg {
  width: 16px;
  height: 16px;
}
.view {
  color: red;
}
.flex > span {
  color: var(--color-font);
}
.el-tag {
  margin: 0 2px;
  height: 20px;
}
#card-content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  grid-auto-rows: 186px;
  gap: 10px;
  scrollbar-width: none;
  > div {
    position: relative;
  }
}

.card {
  height: 100%;
  width: 100%;
  background-color: var(--color2);
  border-radius: var(--radius);
  box-shadow: 0 2px 2px 0 var(--color3);
}
.card:hover {
  outline: 2px solid var(--color3);
}

nav {
  height: 16%;
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-gap: 0 10px;
  border-bottom: 2px solid var(--color1);
  align-items: center;
  > span {
    font-size: 110%;
    font-weight: bolder;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 1px;
  }
  > a {
    white-space: nowrap;
    img {
      width: 24px;
      height: 24px;
      vertical-align: middle;
      border-radius: var(--radius);
    }
    b {
      vertical-align: middle;
      font-size: 16px;
      margin: 0 8px;
    }
  }
}

footer {
  display: flex;
  position: absolute;
  bottom: 0;
  justify-content: space-between;
  width: 100%;
  border-top: 2px solid var(--color1);
  padding: 2px 6px;
  box-sizing: border-box;
  > span {
    font-size: 14px;
    padding: 0 2px;
  }
  > .card-views {
    > img {
      float: left;
      width: 16px;
      height: 16px;
    }
    > span {
      float: left;
      margin: 0 2px;
    }
  }
}
</style>
